import React from 'react';
import { withRouter } from "react-router-dom";
import {connect} from 'react-redux';
// 由于此组件没有参与传参，顾没有this.props的值，需要使用withRouter包裹一下，挂在this.props上

import {authInfo} from '../../redux/registerRedux';
class AuthRouter extends React.Component{
    componentDidMount() {
        // 判断路由中地址为login或者register，不用发起请求
        let loginRegister = ['/login','/register'];
        console.log(this.props);
        let pathName = this.props.location.pathname;
        if(loginRegister.indexOf(pathName) > -1) {
            return;
        }
        this.props.authInfo(this);
    };
    render() {
        return null;
    }
}

const mapDispathToProps = {authInfo};
export default withRouter(connect(null,mapDispathToProps)(AuthRouter));